package hw20170814.q1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Login {
	private Connection conn = null;
	private Statement stm = null;
	private PreparedStatement pst= null;
	private ResultSet rs = null;
	private Dbutil db = new Dbutil();

	public String login(String username, String userpwd) {
		String a = "登陆失败";
		String sql = " select * from li_t_login l where l.username='" + username
				+ "' and l.userpwd='" + userpwd+"'";
		try {
			conn = db.getConnection();
			stm = conn.createStatement();
			rs = stm.executeQuery(sql);
			if (rs.next()) {
				a="登陆成功";
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			db.closeAll();
		}

		return a;
	}
	
	
	public String login1(String username, String userpwd) {
		String a = "登陆失败";
		String sql = " select * from li_t_login l where l.username='" + username
				+ "' and l.userpwd='" + userpwd+"'";
		try {
			conn = db.getConnection();
			pst = conn.prepareStatement(sql);
			rs  = pst.executeQuery();
			if (rs.next()) {
				a="登陆成功";
			}

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			db.closeAll();
		}

		return a;
	}

}
